package com.cy.store.config;

import com.cy.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 处理器拦截器的注册
 * @author: AngJie
 * @create: 2022-02-06 18:31
 **/
@Configuration
public class LoginInterceptorConfigurer implements WebMvcConfigurer {

    // 配置自定义的拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //创建自定义的拦截器对象
        HandlerInterceptor interceptor = new LoginInterceptor();

        //配置白名单
        List<String> whiteList = new ArrayList<>();
        whiteList.add("/bootstrap3/**");
        whiteList.add("/css/**");
        whiteList.add("/images/**");
        whiteList.add("/js/**");
        whiteList.add("/web/register.html");
        whiteList.add("/web/login.html");
        whiteList.add("/web/index.html");
        whiteList.add("/web/product.html");
        whiteList.add("/users/regist");
        whiteList.add("/users/login");
        whiteList.add("/products/**");
        whiteList.add("/");
        whiteList.add("/index.html");



        //完成拦截器的注册
        registry.addInterceptor(interceptor)
        .addPathPatterns("/**")
                //添加白名单
        .excludePathPatterns(whiteList);
    }
}
